import React, { Component } from 'react';
import { connect } from 'dva';
import styles from './../Users.css';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'  
import * as com from '../../../utils/common';

const daoName = "CompAccoFlow";
const columns = [   
  { title: '客户名称', dataIndex: 'CUNM', key: 'CUNM', width: 220, sorter: true, dispaly: true, filter: true },
  { title: '科目', dataIndex: 'ITNM', key: 'ITNM', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '账号', dataIndex: 'ACNO', key: 'ACNO', width: 260, sorter: true, dispaly: true, filter: true },
  // { title: '子账号', dataIndex: 'BANO', key: 'BANO', width: 100, sorter: true, dispaly: true, filter: true },
  { title: '开户日期', key: 'OPDT', render: data => datetime.format(data.OPDT, "yyyy-MM-dd"), width: 120, sorter: true, dispaly: true, filter: true },
  { title: '起息日', width: 100, sorter: true, key: 'VLDT', caption: "VLDT", dispaly: true, filter: true, render: data => datetime.format(data.VLDT, "yyyy-MM-dd") },
  { title: '到期日', width: 100, sorter: true, key: 'MADT', caption: "MADT", dispaly: true, filter: true, render: data => datetime.format(data.MADT, "yyyy-MM-dd") },
  { title: '存期', width: 100, sorter: true, dataIndex: 'RDNM', key: 'RDNM', dispaly: true, filter: true },
  { title: '余额', className: 'column-money', render: data => com.formatNumber(data.ACBL), caption: "ACBL", key: 'ACBL', width: 150, sorter: true, dispaly: true, filter: true },

  // { title: '余额', width: 110, sorter: true, dataIndex: 'ACBL', key: 'ACBL', dispaly: true, filter: true },
  { title: '年日均', className: 'column-money', render: data => com.formatNumber(data.YEAL), caption: "YEAL", key: 'YEAL', width: 150, sorter: true, dispaly: true, filter: true },
];
let controls = [
  { name: 'CUNM', required: true, type: 'text', label: '客户名称', dataType: "string", grid: 12 / 24 },
  { name: 'ITNM', required: true, type: 'text', label: '科目', dataType: "string", grid: 12 / 24 },
  { name: 'ACNO', required: true, type: 'text', label: '账号', dataType: "string", grid: 12 / 24 },
  // { name: 'BANO', required: true, type: 'text', label: '子账号', dataType: "string", grid: 12 / 24 },
  { name: 'OPDT', required: true, type: 'date', label: '开户日期', dataType: "date", grid: 12 / 24 },
  { name: 'VLDT', required: true, type: 'date', label: '起息日', grid: 12 / 24 },
  { name: 'MADT', required: true, type: 'date', label: '到期日', grid: 12 / 24 },
  { name: 'RDNM', required: true, type: 'text', label: '存期', grid: 12 / 24 },
  { name: 'ACBL', required: true, type: 'number', label: '当前余额', grid: 12 / 24 },
  { name: 'YEAL', required: true, type: 'number', label: '开户日均', grid: 12 / 24 },
];
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
class Comp_Clie_Zhxx extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataChange: false
    };
  }
  componentDidMount() {
    this.loadData(this.props.acid)
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.acid != this.props.acid) {
      this.loadData(nextProps.acid)
    }
  }
  loadData(acid) {
    let seeks = [];
    let whereItems = [];
    whereItems.push({
      FieldName: "ID",
      Operator: "in",
      FieldValues: '' + acid
    })
    seeks.push({
      WhereItems: whereItems,
      RelationSign: "AND"
    })
    this.state.diviDataSource = [];
    this.props.dispatch({
      type: `${daoName}/fetch`,
      payload: { daoName, seeks }
    });
  }
  loadOptionData() {
    let options = []
    controls.map(c => {
      if (c.fetch) {
        let f = c.fetch;
        if (c.type === 'cascader-select') {
          f.isCascader = true;
        }
        if (c.type !== 'search') {
          options.push(f);
        }
      }
    })
    if (daoName && options.length > 0) {
      this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
    }
  }
  render() {
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div>
          <div className={styles.create}>
          </div>
          <DataTable ref="RoleTable" daoName={daoName} columns={columns} controls={controls} permID={2026} />
        </div>
      </div>
    )
  }
}
function mapStateToProps(state) {
  const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
  const { userID, orgID, pOrgID, popedomTypes } = state.menus;
  return {
    userID,
    orgID,
    pOrgID,
    popedomTypes,
    showEdit,
    selectedRowKeys,
    keyName,
    record
  }
}
Comp_Clie_Zhxx = connect(mapStateToProps)(Comp_Clie_Zhxx)
export default Comp_Clie_Zhxx;

let render = (props) => React.createElement(Comp_Clie_Zhxx, props);
let f = new Factory()
f.set("Comp_Clie_Zhxx", render)
